function abc() { console.log(" a is " + a); var a =5; console.log("after a is " + a); }
这是因为吊装而变成的
function abc() { var a; console.log(" a is " + a); // undefined a =5; console.log("after a is " + a); // 5 }
javascript具有词法范围,因此该函数a
在查看外部之前会自行查找,因为它找到了a = 5
,它将提升它的声明.